From 45d77dac8331701ceb35d88592f9d069b6902de4 Mon Sep 17 00:00:00 2001 From: Brian Koropoff Date: Thu, 28 Aug 2014 23:36:28 -0700 Subject: [PATCH] Fix build breakage due to generalized type parameter and object bounds It is worth noting that cargo was actually creating trait boxes that contain non-static references, so I couldn't just put 'static everywhere to appease rustc. --- src/cargo/core/registry.rs | 4 +-- src/cargo/core/resolver.rs | 2 +- src/cargo/core/shell.rs | 48 ++++++++++++------------- src/cargo/core/source.rs | 52 ++++++++++++++-------------- src/cargo/lib.rs | 2 +- src/cargo/ops/cargo_compile.rs | 2 +- src/cargo/ops/cargo_rustc/context.rs | 2 +- src/cargo/sources/git/source.rs | 2 +- src/cargo/util/config.rs | 2 +- 9 files changed, 58 insertions(+), 58 deletions(-) diff --git a/src/cargo/core/registry.rs b/src/cargo/core/registry.rs index 789bf1490..236f7e68c 100644 --- a/src/cargo/core/registry.rs +++ b/src/cargo/core/registry.rs @@ -16,7 +16,7 @@ impl Registry for Vec { } pub struct PackageRegistry<'a> { - sources: SourceMap, + sources: SourceMap<'a>, overrides: Vec, config: &'a mut Config<'a> } @@ -53,7 +53,7 @@ impl<'a> PackageRegistry<'a> { Ok(ret) } - pub fn move_sources(self) -> SourceMap { + pub fn move_sources(self) -> SourceMap<'a> { self.sources } diff --git a/src/cargo/core/resolver.rs b/src/cargo/core/resolver.rs index 92d81d8dd..3e5f6b90c 100644 --- a/src/cargo/core/resolver.rs +++ b/src/cargo/core/resolver.rs @@ -216,7 +216,7 @@ impl fmt::Show for Resolve { } } -struct Context<'a, R> { +struct Context<'a, R:'a> { registry: &'a mut R, resolve: Resolve, diff --git a/src/cargo/core/shell.rs b/src/cargo/core/shell.rs index 5e93c0cb4..9c741e1ab 100644 --- a/src/cargo/core/shell.rs +++ b/src/cargo/core/shell.rs @@ -10,34 +10,34 @@ pub struct ShellConfig { pub tty: bool } -enum AdequateTerminal { - NoColor(Box), - Color(Box>>) +enum AdequateTerminal<'a> { + NoColor(Box), + Color(Box>+'a>) } -pub struct Shell { - terminal: AdequateTerminal, +pub struct Shell<'a> { + terminal: AdequateTerminal<'a>, config: ShellConfig } -pub struct MultiShell { - out: Shell, - err: Shell, +pub struct MultiShell<'a> { + out: Shell<'a>, + err: Shell<'a>, verbose: bool } pub type Callback<'a> = |&mut MultiShell|:'a -> IoResult<()>; -impl MultiShell { - pub fn new(out: Shell, err: Shell, verbose: bool) -> MultiShell { +impl<'a> MultiShell<'a> { + pub fn new(out: Shell<'a>, err: Shell<'a>, verbose: bool) -> MultiShell<'a> { MultiShell { out: out, err: err, verbose: verbose } } - pub fn out(&mut self) -> &mut Shell { + pub fn out(&mut self) -> &mut Shell<'a> { &mut self.out } - pub fn err(&mut self) -> &mut Shell { + pub fn err(&mut self) -> &mut Shell<'a> { &mut self.err } @@ -72,17 +72,17 @@ impl MultiShell { } } -pub type ShellCallback<'a> = |&mut Shell|:'a -> IoResult<()>; +pub type ShellCallback<'a> = |&mut Shell<'a>|:'a -> IoResult<()>; -impl Shell { - pub fn create(out: Box, config: ShellConfig) -> Shell { +impl<'a> Shell<'a> { + pub fn create(out: Box, config: ShellConfig) -> Shell<'a> { if config.tty && config.color { - let term: Option>> = Terminal::new(out); + let term: Option>> = Terminal::new(out); term.map(|t| Shell { - terminal: Color(box t as Box>>), + terminal: Color(box t as Box>>), config: config }).unwrap_or_else(|| { - Shell { terminal: NoColor(box stderr() as Box), config: config } + Shell { terminal: NoColor(box stderr() as Box), config: config } }) } else { Shell { terminal: NoColor(out), config: config } @@ -121,8 +121,8 @@ impl Shell { } } -impl Terminal> for Shell { - fn new(out: Box) -> Option { +impl<'a> Terminal> for Shell<'a> { + fn new(out: Box) -> Option> { Some(Shell { terminal: NoColor(out), config: ShellConfig { @@ -168,18 +168,18 @@ impl Terminal> for Shell { } } - fn unwrap(self) -> Box { + fn unwrap(self) -> Box { fail!("Can't unwrap a Shell"); } - fn get_ref<'a>(&'a self) -> &'a Box { + fn get_ref<'b>(&'b self) -> &'b Box { match self.terminal { Color(ref c) => c.get_ref(), NoColor(ref w) => w } } - fn get_mut<'a>(&'a mut self) -> &'a mut Box { + fn get_mut<'b>(&'b mut self) -> &'b mut Box { match self.terminal { Color(ref mut c) => c.get_mut(), NoColor(ref mut w) => w @@ -187,7 +187,7 @@ impl Terminal> for Shell { } } -impl Writer for Shell { +impl<'a> Writer for Shell<'a> { fn write(&mut self, buf: &[u8]) -> IoResult<()> { match self.terminal { Color(ref mut c) => c.write(buf), diff --git a/src/cargo/core/source.rs b/src/cargo/core/source.rs index 7c1b2f11f..1a92b6052 100644 --- a/src/cargo/core/source.rs +++ b/src/cargo/core/source.rs @@ -244,10 +244,10 @@ impl SourceId { } } - pub fn load(&self, config: &mut Config) -> Box { + pub fn load<'a>(&self, config: &'a mut Config) -> Box { log!(5, "loading SourceId; {}", self); match self.kind { - GitKind(..) => box GitSource::new(self, config) as Box, + GitKind(..) => box GitSource::new(self, config) as Box, PathKind => { let path = match self.url.to_file_path() { Ok(p) => p, @@ -255,7 +255,7 @@ impl SourceId { }; box PathSource::new(&path, self) as Box }, - RegistryKind => box DummyRegistrySource::new(self) as Box, + RegistryKind => box DummyRegistrySource::new(self) as Box, } } @@ -267,17 +267,17 @@ impl SourceId { } } -pub struct SourceMap { - map: HashMap> +pub struct SourceMap<'a> { + map: HashMap> } -pub type Sources<'a> = Values<'a, SourceId, Box>; -pub type SourcesMut<'a> = iter::Map<'static, (&'a SourceId, &'a mut Box), - &'a mut Source, - MutEntries<'a, SourceId, Box>>; +pub type Sources<'a> = Values<'a, SourceId, Box>; +pub type SourcesMut<'a> = iter::Map<'static, (&'a SourceId, &'a mut Box), + &'a mut Source+'a, + MutEntries<'a, SourceId, Box>>; -impl SourceMap { - pub fn new() -> SourceMap { +impl<'a> SourceMap<'a> { + pub fn new() -> SourceMap<'a> { SourceMap { map: HashMap::new() } @@ -287,27 +287,27 @@ impl SourceMap { self.map.contains_key(id) } - pub fn get(&self, id: &SourceId) -> Option<&Source> { + pub fn get(&self, id: &SourceId) -> Option<&Source+'a> { let source = self.map.find(id); source.map(|s| { - let s: &Source = *s; + let s: &Source+'a = *s; s }) } - pub fn get_mut(&mut self, id: &SourceId) -> Option<&mut Source> { + pub fn get_mut(&mut self, id: &SourceId) -> Option<&mut Source+'a> { self.map.find_mut(id).map(|s| { - let s: &mut Source = *s; + let s: &mut Source+'a = *s; s }) } - pub fn get_by_package_id(&self, pkg_id: &PackageId) -> Option<&Source> { + pub fn get_by_package_id(&self, pkg_id: &PackageId) -> Option<&Source+'a> { self.get(pkg_id.get_source_id()) } - pub fn insert(&mut self, id: &SourceId, source: Box) { + pub fn insert(&mut self, id: &SourceId, source: Box) { self.map.insert(id.clone(), source); } @@ -315,26 +315,26 @@ impl SourceMap { self.map.len() } - pub fn sources(&self) -> Sources { + pub fn sources(&'a self) -> Sources<'a> { self.map.values() } - pub fn sources_mut(&mut self) -> SourcesMut { - self.map.mut_iter().map(|(_, v)| { let s: &mut Source = *v; s }) + pub fn sources_mut(&'a mut self) -> SourcesMut<'a> { + self.map.mut_iter().map(|(_, v)| { let s: &mut Source+'a = *v; s }) } } -pub struct SourceSet { - sources: Vec> +pub struct SourceSet<'a> { + sources: Vec> } -impl SourceSet { - pub fn new(sources: Vec>) -> SourceSet { +impl<'a> SourceSet<'a> { + pub fn new(sources: Vec>) -> SourceSet<'a> { SourceSet { sources: sources } } } -impl Registry for SourceSet { +impl<'a> Registry for SourceSet<'a> { fn query(&mut self, name: &Dependency) -> CargoResult> { let mut ret = Vec::new(); @@ -346,7 +346,7 @@ impl Registry for SourceSet { } } -impl Source for SourceSet { +impl<'a> Source for SourceSet<'a> { fn update(&mut self) -> CargoResult<()> { for source in self.sources.mut_iter() { try!(source.update()); diff --git a/src/cargo/lib.rs b/src/cargo/lib.rs index 8144eb396..f01277bb4 100644 --- a/src/cargo/lib.rs +++ b/src/cargo/lib.rs @@ -150,7 +150,7 @@ pub fn process_executed<'a, } } -pub fn shell(verbose: bool) -> MultiShell { +pub fn shell(verbose: bool) -> MultiShell<'static> { let tty = stderr_raw().isatty(); let stderr = box stderr() as Box; diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 8b686af2d..23b0cf12f 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -36,7 +36,7 @@ use util::{CargoResult, Wrap, config, internal, human, ChainError, profile}; pub struct CompileOptions<'a> { pub update: bool, pub env: &'a str, - pub shell: &'a mut MultiShell, + pub shell: &'a mut MultiShell<'a>, pub jobs: Option, pub target: Option<&'a str>, pub dev_deps: bool, diff --git a/src/cargo/ops/cargo_rustc/context.rs b/src/cargo/ops/cargo_rustc/context.rs index cfa62bdc2..6ee234b2a 100644 --- a/src/cargo/ops/cargo_rustc/context.rs +++ b/src/cargo/ops/cargo_rustc/context.rs @@ -19,7 +19,7 @@ pub struct Context<'a, 'b> { pub rustc_version: String, pub config: &'b mut Config<'b>, pub resolve: &'a Resolve, - pub sources: &'a SourceMap, + pub sources: &'a SourceMap<'b>, pub compilation: Compilation, env: &'a str, diff --git a/src/cargo/sources/git/source.rs b/src/cargo/sources/git/source.rs index b0198dd95..c3d80132f 100644 --- a/src/cargo/sources/git/source.rs +++ b/src/cargo/sources/git/source.rs @@ -12,7 +12,7 @@ use sources::git::utils::{GitReference, GitRemote, Master, Other, GitRevision}; /* TODO: Refactor GitSource to delegate to a PathSource */ -pub struct GitSource<'a, 'b> { +pub struct GitSource<'a, 'b:'a> { remote: GitRemote, reference: GitReference, db_path: Path, diff --git a/src/cargo/util/config.rs b/src/cargo/util/config.rs index 6e03115ac..01e544383 100644 --- a/src/cargo/util/config.rs +++ b/src/cargo/util/config.rs @@ -9,7 +9,7 @@ use util::toml as cargo_toml; pub struct Config<'a> { home_path: Path, - shell: &'a mut MultiShell, + shell: &'a mut MultiShell<'a>, jobs: uint, target: Option, linker: Option, -- 2.30.2